home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Libraries / SAT / SATcollision][ ƒ / sApple][.c next >
Encoding:
C/C++ Source or Header  |  1993-09-21  |  2.0 KB  |  86 lines  |  [TEXT/KAHL]

  1. /* Apple sprite for SATcollision][ */
  2. /* No, it has nothing to do with old Apple computers :-) */
  3.  
  4. /* unit sApple; */
  5.  
  6. #include "SAT.h"
  7. #include "SATcollision][.h"
  8.  
  9.     static Handle    nammSound, bliaehSound;
  10.     static FacePtr    goodFace, badFace;
  11.     static FacePtr    coreDump;
  12.  
  13.  
  14.     void InitApple()
  15.     {
  16.         int i;
  17.         
  18.         nammSound = SATGetNamedSound("\Pnamm");
  19.         bliaehSound = SATGetNamedSound("\Pbliaeh");
  20.         goodFace = GetFace(132);
  21.         badFace = GetFace(133);
  22.         coreDump = GetFace(135);
  23.     }
  24.  
  25.     pascal void SetupApple (SpritePtr me)
  26.     {
  27.         me->speed.h = 1 + Rand(3);
  28.         me->kind = -2; /*Enemy kind*/
  29.         me->face = goodFace;
  30.         SetRect(&me->hotrect, 0, 0, 32, 32);
  31.     }
  32.  
  33. /*We use kind -2 for fresh apples and kind -3 for bad apples. We avoid -1, since it doesn't count for the "anymonsters" flag.*/
  34. /*Note that the "kind" field is not modified my SAT since we are not using KindCollision!*/
  35.  
  36.     pascal void HandleApple (SpritePtr me)
  37.     {
  38.         switch (me->kind) {
  39.             case -2: 
  40.                 me->face = goodFace;
  41.                 break;
  42.             case -3: 
  43.                 me->face = badFace;
  44.                 break;
  45.         }; /*switch*/
  46.  
  47.         me->position.h = me->position.h + me->speed.h;
  48.         if (me->position.h > offSizeH - 16)
  49.             {
  50.                 me->speed.h = -1 - Rand(3);
  51.                 if (Rand(2) == 0)
  52.                     me->kind = -3;
  53.                 else
  54.                     me->kind = -2;
  55.             };
  56.         if (me->position.h < -16)
  57.             {
  58.                 me->speed.h = 1 + Rand(3);
  59.                 if (Rand(2) == 0)
  60.                     me->kind = -3;
  61.                 else
  62.                     me->kind = -2;
  63.             };
  64.     }
  65.  
  66.     pascal void HitApple(SpritePtr me, SpritePtr him)
  67.     {
  68.         if (him->task == &HandleApple)
  69.             me->kind = -3; /*Colliding apples corrupt each other!*/
  70.         else
  71. /*If "him" is not an apple, then it must be the player!*/
  72.             if (him->mode >= 0) /*if the player feels bad, don't eat*/
  73.                 switch (me->kind) {
  74.                     case -2:
  75.                             SATSoundPlay(nammSound, 1, false);
  76.                             me->task = nil;
  77.                             him->mode = 25;
  78.                             SATPlotFace(coreDump, nil, nil, me->position, true);
  79.                             break;
  80.                     case -3: /*Bad apple, make player feel bad.*/
  81.                             him->mode = -20;
  82.                             SATSoundPlay(bliaehSound, 2, false);
  83.                             break;
  84.                 };
  85.     }
  86.